package com.ruoyi.web.controller.material;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.material.MaterialPropertyType;
import com.ruoyi.system.service.IMaterialPropertyTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/3/6 14:20
 */
@Api(tags = "自定义类型属性")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/material/property")
public class MaterialPropertyTypeController  extends BaseController {

    @Autowired
    IMaterialPropertyTypeService iMaterialPropertyTypeService;

    /**
     * 查询物料属性类型列表
     */
    @ApiOperation(value = "查询自定义类型")
    @PostMapping("/list")
    public TableDataInfo list(MaterialPropertyType baseTeam)
    {
        startPage();
        LambdaQueryWrapper<MaterialPropertyType> lqw = new LambdaQueryWrapper<MaterialPropertyType>();
        List<MaterialPropertyType> list = iMaterialPropertyTypeService.list(lqw);
        return getDataTable(list);
    }


    /**
     * 新增物料属性类型
     */
    @Log(title = "物料单位" , businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增自定义类型")
    @PostMapping
    public AjaxResult add(@RequestBody MaterialPropertyType baseTeam) {
        return toAjax(iMaterialPropertyTypeService.save(baseTeam) ? 1 : 0);
    }

    /**
     * 修改物料属性类型
     */
    @Log(title = "物料单位" , businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改自定义类型")
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialPropertyType baseTeam) {
        return toAjax(iMaterialPropertyTypeService.updateById(baseTeam) ? 1 : 0);
    }

    /**
     * 删除物料属性类型
     */
    @Log(title = "物料单位" , businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除自定义类型")
    @DeleteMapping("/{teamIds}" )
    public AjaxResult remove(@PathVariable Long[] teamIds) {
        return toAjax(iMaterialPropertyTypeService.removeByIds(Arrays.asList(teamIds)) ? 1 : 0);
    }
}
